﻿//-----------------------------------------------------------------------
// <copyright file="SnapState.cs" company="Nathan Miller">
// Copyright (c) Nathan Miller.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//-----------------------------------------------------------------------
namespace TileTool.Base.Editor.Transform
{
    using TileTool.Common.Math;
    using TileTool.Editor.Transform;

    /// <summary>
    /// Snap state implementation.
    /// </summary>
    public class SnapState : ISnapState
    {
        #region Constants - Private

        /// <summary>
        /// Translate snap default values.
        /// </summary>
        private static readonly MinMaxDefault<float> TranslateSnapDefaultValues = new MinMaxDefault<float>(0.001f, 1024.0f, 8.0f);

        /// <summary>
        /// Rotate snap default values.
        /// </summary>
        private static readonly MinMaxDefault<float> RotateSnapDefaultValues = new MinMaxDefault<float>(0.001f, 360.0f, 30.0f);

        #endregion

        #region Fields - Private

        /// <summary>
        /// Translate snap amount.
        /// </summary>
        private float translateSnapAmount;

        /// <summary>
        /// Rotate snap degrees.
        /// </summary>
        private float rotateSnapDegrees;

        #endregion

        #region Constructor

        /// <summary>
        /// Default constructor.
        /// </summary>
        public SnapState()
        {
            this.translateSnapAmount = TranslateSnapDefaultValues.Default;
            this.rotateSnapDegrees = RotateSnapDefaultValues.Default;
        }

        #endregion

        #region Properties - Public

        /// <summary>
        /// Gets if we should snap to the world grid grid.
        /// </summary>
        public bool SnapToGrid
        {
            get;
            set;
        }

        /// <summary>
        /// Gets if we should snap our translate amount.
        /// </summary>
        public bool TranslateSnap
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the translate snap amount.
        /// </summary>
        public float TranslateSnapAmount
        {
            get
            {
                return this.translateSnapAmount;
            }

            set
            {
                this.translateSnapAmount = TranslateSnapDefaultValues.Clamp(value);
            }
        }

        /// <summary>
        /// Gets if we should snap our rotation amount.
        /// </summary>
        public bool RotateSnap
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the rotation snap amount in degrees.
        /// </summary>
        public float RotateSnapDegrees
        {
            get
            {
                return this.rotateSnapDegrees;
            }

            set
            {
                this.rotateSnapDegrees = RotateSnapDefaultValues.Clamp(value);
            }
        }

        #endregion
    }
}
